package com.frank.demo.controller;/*
 *@author:xec
 *@date:2022/2/23  11:07
 */

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
public class TestController {

    private static final Logger LOG = LoggerFactory.getLogger(TestController.class);

    @Resource
    private RedisTemplate redisTemplate;

    @Value("${name:a}")
    public String name ;

    @GetMapping("/hello")
    public String hello(){
        return "hello world " + name;
    }

    @RequestMapping("/redis/set/{key}/{value}")
    public String set(@PathVariable Long key,@PathVariable String value){
        redisTemplate.opsForValue().set(key,value,3600, TimeUnit.SECONDS);
        LOG.info("key:{},value:{}",key,value);
        return "success";
    }
    @RequestMapping("/redis/get/{key}")
    public Object get(@PathVariable Long key){
        Object object = redisTemplate.opsForValue().get(key);
        LOG.info("key:{},value:{}",key,object);
        return object;
    }

}
